mc.table <- function(nsims, param.list, nn.list, traindata, namefunc = NULL, classify = NULL){
	track.df <- expand.grid(1:length(nn.list), 1:length(param.list))
	train.list <- foreach(aa = 1:ncol(traindata)) %dopar% {traindata[,aa]}
	if(!is.null(classify) + !is.null(namefunc) == 2){return(print('Choose one.'))}
	if(!is.null(classify)){
	store.list <- foreach(jj = 1:nrow(track.df)) %:% 
		foreach(ll = 1:nsims, .combine = 'c') %dopar% {
			NN <- nn.list[[track.df$Var1[jj]]]
			params <- param.list[[track.df$Var2[jj]]]
			sim.data <- unlist(mapply(train.list, FUN = sampfunc, tmpparam = params, MoreArgs = list(rnx = row.names(traindata), tmpNN = NN)))
			ttrain <-as.list(as.data.frame(t(classify[sim.data,])))
			tout <- colnames(classify)[unlist(lapply(ttrain, sample, x = 1:length(colnames(classify)), size = 1, replace = T))]
			tout <- factor(tout, levels = colnames(classify))
			res <- prop.table(table(tout))
			res <- res[colnames(classify)]
			mae <- mean(abs(res - params))
			return(mae)
		}
	}
	if(!is.null(namefunc)){
		store.list <- foreach(jj = 1:nrow(track.df)) %:% 
			foreach(ll = 1:nsims, .combine = 'c') %dopar% {
			NN <- nn.list[[track.df$Var1[jj]]]
			params <- param.list[[track.df$Var2[jj]]]
			sim.data <- unlist(mapply(train.list, FUN = sampfunc, tmpparam = params, MoreArgs = list(rnx = row.names(traindata), tmpNN = NN)))
			sim.data <- prop.table(table(sim.data))
			ests <- namefunc(cond = traindata, targ = sim.data)
			mae <- mean(abs(ests - params))
			return(mae)
			}
	}
	point.df <- matrix(NA, nrow = length(nn.list), ncol = length(param.list))
	se.df <- matrix(NA, nrow = length(nn.list), ncol = length(param.list))
	for(jj in 1:nrow(track.df)){
		point.df[track.df[jj,1], track.df[jj,2]] <- mean(store.list[[jj]])
		se.df[track.df[jj,1], track.df[jj,2]] <- sd(store.list[[jj]])
	}
	ret <- list(store = store.list, point = point.df, se = se.df)
	return(ret)
}